<template>
    <PanelBox :image="image">
        <div class="regional-distribution-box">
            <BPie class="pie-box" :data="dataList" :sum="sum" />
            <div class="line-box">
                <BBar
                    class="line-small"
                    v-for="(item, index) in dataList"
                    :key="index"
                    :name="item.name"
                    :value="item.value"
                    :sum="sum"
                    :color="item.color"
                />
            </div>
        </div>
    </PanelBox>
</template>

<script>
import PanelBox from "@/component/PanelBox";
import BPie from "./component/BPie";
import BBar from "./component/BBar";
import { FetchGetTailingHeadLibrary } from "@/api";

export default {
    name: "RegionalDistribution",

    components: {
        PanelBox,
        BPie,
        BBar,
    },

    props: {
        image: {
            type: String,
            default() {
                return "";
            },
        },
    },

    data() {
        return {
            dataList: [
                // {
                //     name: "泉州头顶库",
                //     value: 2,
                // },
                // {
                //     name: "龙岩头顶库",
                //     value: 3,
                // },
                // {
                //     name: "三明头顶库",
                //     value: 1,
                // },
            ],
            // color: ["#CB95FB", "#BFFF3F", "#4C67FF"],
            sum: 0,
        };
    },

    created() {
        this.refreshList();
    },

    methods: {
        refreshList() {
            FetchGetTailingHeadLibrary().then((res) => {
                this.dataList = res.map((item) => ({
                    name: item.areaName,
                    value: item.count,
                }));
                this.sum = eval(res.map((item) => item.count).join("+"));
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.regional-distribution-box {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .pie-box {
        width: 50%;
        height: 100%;
    }
    .line-box {
        width: 50%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: flex-start;
        .line-small {
            width: 90%;
            height: 26px;
        }
    }
}
</style>
